#!/usr/bin/env bash
# This script runs clippy with the most common configurations.
# Arguments given will be passed through to "cargo clippy"
# This runs in the Makefile environment via "make run"

set -euo pipefail

# Run from the Makefile environment
MAKEFILE_RUN=${MAKEFILE_RUN:-""}
if [[ -z $MAKEFILE_RUN ]] ; then
	COMMAND="$0 $*" exec make run
fi
SHELL_DEBUG=${SHELL_DEBUG:-""}
if [[ -n "$SHELL_DEBUG" ]] ; then
  set -x
fi

CLIPPY_LINTS=(-A clippy::module_inception  \
	-A clippy::should_implement_trait \
	-A clippy::too_many_arguments \
	-A clippy::blacklisted_name \
	-A clippy::redundant_closure \
	-A clippy::upper_case_acronyms \
	-A clippy::field_reassign_with_default \
	-A clippy::wrong_self_convention \
	-A clippy::needless_range_loop \
	-A clippy::inconsistent_struct_constructor \
	-A clippy::new_ret_no_self \
	-A clippy::unnecessary_sort_by \
	-A clippy::unnecessary_wraps \
	-A clippy::bool_assert_comparison \
	-A clippy::self_named_constructor \
	-A clippy::enum_variant_names \
        -W clippy::dbg_macro \
        -W clippy::todo \
        -D rust-2018-idioms)

cargo clippy --workspace \
	--exclude fuzz-targets --exclude fuzzer-honggfuzz --exclude fuzzer-afl --exclude fuzzer-libfuzzer \
	--features "${TIKV_ENABLE_FEATURES}" "$@" -- "${CLIPPY_LINTS[@]}"
